<template>
  <div class="main">
    <div class="top-search">
      <img src="../../images/goodsshow.png" alt="商品秀" />
      <div class="search-box">
        <input type="text" class="search-text" />
        <input type="submit" value="搜索" class="search-button" />
      </div>
    </div>

    <div class="content">

      <!-- 渲染数据样式 -->
      <div class="content-item" v-for="item in sensorsList" :key="item.id">
        <img :src="'http://39.96.195.154:8080/upload/' + item.sensor_picture" alt="sensor picture" />
        <div class="content-info">
          <p class="price">￥{{ item.sensor_price | numFilter }}</p>
          <router-link :to="'/shops/Commodity/'+item.id">
            <span >{{ item.sensor_name }}</span>
          </router-link>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
import httpRequest from "../../tools/ajax.js"

export default {
  data: function() {
    return {
      sensorsList: []
    };
  },
  created(){
    this.getAllStoreList();
  },
  methods: {
    getAllStoreList() {
      var paramObj = {
        httpUrl: "http://39.96.195.154:8080/checkAllStoreList",
        type: "get",
        data: {}
      };
      httpRequest(
        paramObj,
        (respondDada) => {
          respondDada = JSON.parse(respondDada);
          // console.log(respondDada.data);
          this.sensorsList = respondDada.data.rows;

        },
        function() {
          alert("网络错误");
        }
      );
    }
  },
  filters: {
			numFilter(value) {
				// 截取当前数据到小数点后1位
				let realVal = parseFloat(value).toFixed(2);
				return realVal;
			}
		}
};
</script>

<style lang='less' scoped>
.main {
  a {
    color: #f40;
  }
  a:hover {
    text-decoration: underline;
  }
  width: 100%;
  .top-search {
    display: flex;
    align-items: center;
    img {
      width: 200px;
      height: 124px;
    }
    .search-box {
      margin-left: 50px;
      width: 800px;
      height: 34px;
      .search-text {
        float: left;
        padding-left: 10px;
        width: 720px;
        height: 34px;
        outline: none;
        font-size: 15px;
        border: 1.2px solid #f40;
      }
      .search-button {
        width: 80px;
        height: 34px;
        border: 0;
        cursor: pointer;
        outline: none;
        font-size: 15px;
        color: white;
        border: 1.2px solid #f40;
        background-color: #f40;
      }
    }
  }
  .content {
    display: flex;
    flex-wrap: wrap;
    cursor: pointer;
    padding: 10px 0 10px 35px;
    width: vw;
    .content-item {
      margin: 0 35px 20px 0;
      padding: 15px;
      width: 200px;
      height: 300px;
      border: 1px solid #eee;
      transition: 0.3s;
      img {
        width: 170px;
        height: 190px;
        border-radius: 2px;
      }
      .content-info {
        padding: 5px;
        width: 170px;
        height: 85px;
        .price {
          margin: 10px 0;
          font-size: 16px;
          font-weight: 600;
          line-height: 16px;
          color: #f40;
        }
        a {
          color: #515a6e;
        }
      }
    }
    .content-item:hover {
      border-color: #f40;
    }
  }
}
</style>
